<template>
  <div role="portal-base-router-box" class="g-width100 g-height100">
    <template v-if="!portalOne">
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive === true"></router-view>
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive"></router-view>
    </template>
    <router-view v-else></router-view>
  </div>
</template>
<script>

    import {installMfe} from '../../common-util/src/components/mfe/index'
    import config from './config'
    // 放在这里会最先执行优先于main.js
    // 开启后端单机运行标识，后端单机运行主要是修改axios请求的基础路径
    window.portalOneBackend = config.portalOneBackend
    installMfe(true)

    export default {
        name: 'app',
        data (){
            return {
                portalOne: process.env.VUE_APP_PORTALONE == 'true'
            }
        },
        created () {
            this.bindLoginBus()
        },
        mounted(){
            // 尝试获取用户信息，如果未登录，去登录页面
            this.axios.get(this.$baseURL.base +  '/base/user/userinfo/current').catch(error =>{
                if (error.response) {
                    let status = error.response.status
                    if(status == 401){
                        this.toLogin()
                    }
                }else{

                    this.$message.error('网络错误或服务不可用')
                }
            })
        },
        methods:{
            bindLoginBus(){
                this.$bus.$on('toLogin',this.toLogin)
            },
            toLogin(){
                this.$router.replace('/login')
            }
        }
    }
</script>

